package com.smag.web.controller.echarts.cone;

import com.smag.common.annotation.Log;
import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.core.page.TableDataInfo;
import com.smag.common.enums.BusinessType;
import com.smag.common.utils.poi.ExcelUtil;
import com.smag.echarts.domain.EchartsConeEconomy;
import com.smag.echarts.service.EchartsConeEconomyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController("coneEconomyController")
@RequestMapping("/echarts/cone/economy")
public class EconomyController extends BaseController {
    @Resource
    private EchartsConeEconomyService echartsConeEconomyService;
    @GetMapping("/listAll")
    public AjaxResult getEconomyList(){
        return echartsConeEconomyService.getEconomyList();
    }

    /**
     * 查询各城市一年农户平均收入列表
     */
    @PreAuthorize("@ss.hasPermi('system:economy:list')")
    @GetMapping("/list")
    public TableDataInfo list(EchartsConeEconomy echartsConeEconomy)
    {
        startPage();
        List<EchartsConeEconomy> list = echartsConeEconomyService.selectEchartsConeEconomyList(echartsConeEconomy);
        return getDataTable(list);
    }

    /**
     * 导出各城市一年农户平均收入列表
     */
    @PreAuthorize("@ss.hasPermi('system:economy:export')")
    @Log(title = "各城市一年农户平均收入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EchartsConeEconomy echartsConeEconomy)
    {
        List<EchartsConeEconomy> list = echartsConeEconomyService.selectEchartsConeEconomyList(echartsConeEconomy);
        ExcelUtil<EchartsConeEconomy> util = new ExcelUtil<EchartsConeEconomy>(EchartsConeEconomy.class);
        util.exportExcel(response, list, "各城市一年农户平均收入数据");
    }

    /**
     * 获取各城市一年农户平均收入详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:economy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return echartsConeEconomyService.selectEchartsConeEconomyById(id);
    }

    /**
     * 新增各城市一年农户平均收入
     */
    @PreAuthorize("@ss.hasPermi('system:economy:add')")
    @Log(title = "各城市一年农户平均收入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EchartsConeEconomy echartsConeEconomy)
    {
        return echartsConeEconomyService.insertEchartsConeEconomy(echartsConeEconomy);
    }

    /**
     * 修改各城市一年农户平均收入
     */
    @PreAuthorize("@ss.hasPermi('system:economy:edit')")
    @Log(title = "各城市一年农户平均收入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EchartsConeEconomy echartsConeEconomy)
    {
        return echartsConeEconomyService.updateEchartsConeEconomy(echartsConeEconomy);
    }

    /**
     * 删除各城市一年农户平均收入
     */
    @PreAuthorize("@ss.hasPermi('system:economy:remove')")
    @Log(title = "各城市一年农户平均收入", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return echartsConeEconomyService.deleteEchartsConeEconomyByIds(ids);
    }
}
